import Vue from "vue";
import Vuex from "vuex";

Vue.use(Vuex);

const store = new Vuex.Store({
  state: {
    Authorization: localStorage.getItem("Authorization") ? localStorage.getItem("Authorization") : "",
    userInfo: localStorage.getItem("userInfo") ? localStorage.getItem("userInfo") : "",
    currentPageTitle:'首页'
  },
  mutations: {
    changeToken(store, token) {
      store.Authorization = token;
      localStorage.setItem("Authorization", token);
    },
    changeUser(store, userInfo) {
      store.userInfo = userInfo;
      localStorage.setItem("userInfo", userInfo);
    },
    logout(store) {
      store.Authorization = "";
      store.userInfo = "";
      localStorage.removeItem("Authorization");
      localStorage.removeItem("userInfo");
    },
    changeRouter(store,pageTitle){
      store.currentPageTitle=pageTitle
    }
  },
});

export default store;
